<template>
  <el-dropdown @command="commandEvent">
    <svg-icon icon-class="language" />
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item
          command="zh"
          :disabled="$i18n.locale === 'zh'"
        >中文</el-dropdown-item>
        <el-dropdown-item
          command="en"
          :disabled="$i18n.locale === 'en'"
        >English</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script>
import CookieJs from 'js-cookie'
export default {
  name: 'Lang',
  data() {
    return {}
  },
  computed: {},
  created() {
    console.log(this.$i18n)
  },
  methods: {
    commandEvent(command) {
      // 将点击的语言赋值给国际化组件中
      this.$i18n.locale = command
      // 将点击的语言存入CookieJs中
      CookieJs.set('lang', command)
      // 刷新页面
      this.$router.go(0)
    }
  }
}
</script>
<style lang="less" scoped></style>
